﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace WpfControlLibrary
{
    public partial class CustomTaskPaneControl : System.Windows.Forms.UserControl
    {


        private bool isLogin;
        private UserControl profilePage;
        private UserControl listPage;

        private UserControl currentPage;
        private PageType pendingPageType;
        public CustomTaskPaneControl()
        {
            InitializeComponent();
            listPage = new ListPage();
            profilePage = new ProfilePage();
        }

        public void ShowPage(PageType pageType)
        {
            if (pageType == PageType.PROFILE || pageType == PageType.LIST)
            {
                if (!isLoggedIn())
                {
                    LoginPage loginPage = new LoginPage(pageType);
                    loginPage.OnLogin += LoginPage_OnLogin;
                    this.elementHost1.Child = loginPage;
                }
                else
                {
                    showPageInElementHost(pageType);
                }
            }


        }

        private void LoginPage_OnLogin(object sender, LoginEventArgs e)
        {
            isLogin = true;
            showPageInElementHost(e.AfterLoginPage);

        }

        private bool isLoggedIn()
        {

            return isLogin;
        }

        private void showPageInElementHost(PageType page)
        {
            switch (page)
            {
                case PageType.PROFILE:
                    this.elementHost1.Child = profilePage;
                    break;
                case PageType.LIST:
                    this.elementHost1.Child = listPage;
                    break;
            }
        }
    }
}
